package com.hospital.dictionary.module.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hospital.common.core.result.SuccessTip;
import com.hospital.common.core.result.Tip;
import com.hospital.dictionary.constant.CommonConstant;
import com.hospital.dictionary.module.controller.base.BaseController;
import com.hospital.dictionary.module.entity.ClinicItemGuide;
import com.hospital.dictionary.module.entity.ClinicItemGuideValue;
import com.hospital.dictionary.module.service.ClinicItemGuideService;
import com.hospital.dictionary.module.service.ClinicItemGuideValueService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * ÕïÁÆÏîÄ¿Ö¸ÒýÐÅÏ¢Ä£°åÓëÖµ¶ÔÕÕ¹ØÏµÅäÖÃ 前端控制器
 * </p>
 *
 * @author lvyao
 * @since 2024-01-10
 */
@RestController
@RequestMapping("/module/clinicItemGuide")
public class ClinicItemGuideController extends BaseController<ClinicItemGuide, ClinicItemGuideService> {

    @Resource
    private ClinicItemGuideService clinicItemGuideService;

    @Resource
    private ClinicItemGuideValueService clinicItemGuideValueService;

    @Override
    public Tip updateDto(@RequestBody ClinicItemGuide object){
        boolean result = baseService.update(new QueryWrapper<ClinicItemGuide>().eq(CommonConstant.ORDER_DEPT_CODE,object.getOrderDeptCode())
                .eq(CommonConstant.PERFORM_DEPT_CODE,object.getPerformDeptCode())
                .eq(CommonConstant.CLINIC_ITEM_CODE,object.getClinicItemCode()));
        return new SuccessTip(result);
    }

    /**
     * @description:根据key值维护的对照关系 获取所有现在有对照关系
     * @author: lvyao
     * @date: 2024/1/10 15:16
     * @param guideKeyCode:
     * @return: com.hospital.dictionary.result.Tip
     **/
    @GetMapping(value = "/getValueList")
    public Tip getKeyList(@RequestParam(name = "guideKeyCode") String guideKeyCode){
        List<ClinicItemGuide> clinicItemGuideList = clinicItemGuideService.list(new QueryWrapper<ClinicItemGuide>().eq(CommonConstant.GUIDE_KEY_CODE, guideKeyCode));
        List<String> collect = clinicItemGuideList.stream().map(ClinicItemGuide::getGuideValueCode).distinct().collect(Collectors.toList());
        List<ClinicItemGuideValue> clinicItemGuideValues = clinicItemGuideValueService.list(new QueryWrapper<ClinicItemGuideValue>().in(CommonConstant.GUIDE_CODE, collect));
        return new SuccessTip(clinicItemGuideValues);
    }

}

